package com.example.algorithm.string;

/**
 * @author : zhy
 * @since : 2022/7/25
 * 替换空格
 */
public class ReplaceSpace {

    public String replaceSpace(String s) {
        StringBuilder builder = new StringBuilder();
        String[] split = s.split(" ");
        int len=split.length;
        System.out.println(len);
        for(int i=0;i<len-1;i++)
        {
            builder.append(split[i]).append("%20");
        }
        builder.append(split[len-1]);
        return builder.toString();


    }

    public static void main(String[] args) {
        ReplaceSpace space = new ReplaceSpace();
        String s = "We are happy. ";
        String space1 = space.replaceSpace(s);
        System.out.println(space1);
    }
}
